<template>
  <div>
    <el-form ref="shenHeOrderForm" size="small" :model="entity" :rules="rules" label-width="120px">
      <el-form-item label="审核意见" prop="returnReason">
        <el-input type="textarea" v-model="entity.returnReason" :rows="4" placeholder="审核意见" />
      </el-form-item>
      <el-form-item>
        <el-button type="success" @click="onShenHeOrder(GiftOrderStatus.shenHePass)">通过</el-button>
        <el-popconfirm confirmButtonText='确定' cancelButtonText='取消' icon="el-icon-info" iconColor="red"
                       title="确定拒绝订单吗?" @confirm="onShenHeOrder(GiftOrderStatus.shenHeFail)">
          <el-button style="margin-left: 10px" slot="reference" type="danger">拒绝</el-button>
        </el-popconfirm>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import request from "@/utils/request";
import GiftOrderStatus from "@/utils/GiftOrderStatus";
export default {
  props:{
    entityId : {type : Number, default: 0},
  },
  data() {
    return {
      GiftOrderStatus:GiftOrderStatus,
      entity: {
        id : this.entityId,
        returnReason:'同意',
        statusId:0,
      },
      rules: {
        returnReason: [
          { required: true, message: '请填写审核意见', trigger: 'blur' }
        ],
      },
    }
  },
  methods: {
    onShenHeOrder(statusId){
      this.$refs['shenHeOrderForm'].validate((valid) => {
        if(valid){
          this.entity.statusId = statusId
          request({
            url: '/gift/ordershenhe/shenheorder',
            data: this.entity
          }).then( res =>{
            if(res.code === "200"){
              this.$message.success(res.msg)
              this.$emit('update:visible', false);  //关闭弹窗
              this.$EventBus.$emit("ordershenhe", {});
            }else{
              this.$message.error(res.msg);
            }
          })
        }else{
          console.log('error submit!!');
          return false;
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
